<?php
abstract class My_Service
{
	protected $_dao;
	protected $_errorList = array();
	
	public function __construct()
	{
		$className = get_class($this);
		$className = substr($className,0,strlen($className)-7);
		$daoClass  = $className."DAO";
		$this->setDAO(new $daoClass());
	}

	public function setDAO($dao)
	{
		$this->_dao = $dao;
	}

	public function getDAO()
	{
		if (null === $this->_dao) {
			$className = get_class($this);
			$className = substr($className,0,strlen($className)-7);
			$daoClass  = $className."DAO";
			$this->setDAO(new $daoClass());
		}
		return $this->_dao;
	}
	
	public function getTable()
	{
		return $this->getDAO()->getTable();
	}

	public function setErrorMsg($errorMsg)
	{
		$this->_errorList = $errorMsg;
		return $this;
	}

	public function getErrorMsg()
	{
		return $this->_errorList;
	}

	public function load($id)
	{
		return $this->getDAO()->load($id);
	}

	public function loadData($id)
	{
		return $this->getDAO()->loadData($id);
	}

	public function loadAll()
	{
		return $this->getDAO()->loadAll();
	}

	public function loadAllData()
	{
		return $this->getDAO()->loadAllData();
	}

	public function buildQueryData($orderBy = "", $orderDirection="",
	$key = "", $field = "", $params = null)
	{
		return $this->getDAO()->buildQueryData($orderBy,$orderDirection,$key,$field,$params);
	}
	
	public function save($dto)
	{
		$this->getDAO()->save($dto);
	}
	
	public function remove($id)
	{
		return $this->getDAO()->remove($id);
	}
}